home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wdj0797.zip / TUFFS.ZIP / EXCEPT6.CPP < prev    next >
C/C++ Source or Header  |  1997-04-22  |  761b  |  33 lines

  1. // File:        except6
  2. #include <iostream.h>
  3. #include <except.h>
  4. #include <cstring.h>
  5. #include "warning.h"
  6.  
  7. void badFunction()
  8. {
  9.   char *p = new char[10];
  10.   cout << "Setting p to zero..." << endl;
  11.   memset(p, 0, -10);
  12. }
  13. int main()
  14. {
  15.   IssueWarning();
  16.   DWORD code = 0;
  17.   try
  18.   {
  19.     try
  20.     {
  21.       cout << "Calling badFunction()" << endl;
  22.       badFunction();
  23.       cout << "badFunction() completed without exception" << endl;
  24.     } catch (xmsg &x) {
  25.       cerr << "Exception caught '" << x.why() << "'" << endl;
  26.     } catch (...) {
  27.       cerr << "Unknown exception caught" << endl;
  28.     }
  29.   } __except (code=GetExceptionCode(), 1) {
  30.     cerr << "Unknown system exception " << hex << code << " caught" << endl;
  31.   }
  32.   return 0;
  33. }